package com.zmj.sy.mom.srv.aps.service;

import com.zmj.sy.mom.srv.aps.bean.entity.resource.Span;
import com.zmj.sy.mom.srv.aps.bean.vo.base.BaseSelectItemResVo;
import com.zmj.sy.mom.srv.aps.bean.vo.base.BaseSelectResVo;
import com.zmj.sy.mom.srv.aps.mapper.SpanMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@RequiredArgsConstructor
@Service
public class SpanService {

    private final SpanMapper spanMapper;
    public BaseSelectResVo select() {

        List<Span> selectList = spanMapper.selectList(null);
        List<BaseSelectItemResVo> collect = selectList.stream()
                .sorted(Comparator.comparing(Span::getSeq))
                .map(e -> {
                    BaseSelectItemResVo resVo = new BaseSelectItemResVo();
                    resVo.setText(e.getName());
                    resVo.getAttr().put("myCode", e.getMyCode());
                    resVo.setValue(e.getId());
                    return resVo;
                })
                .collect(Collectors.toList());
        return BaseSelectResVo.of(collect);
    }
}
